package ru.teleology.cubefs.api.models.blobmap;

import ru.teleology.cubefs.api.reflection.NativeType;
import ru.teleology.cubefs.api.reflection.Type;
import ru.teleology.cubefs.api.reflection.TypeSystem;
import ru.teleology.cubefs.api.reflection.Types;
import ru.teleology.cubefs.api.reflection.list.array.ByteArray;

@NativeType(name = Types.DATA_TYPE)
public class Data extends ByteArray {

	private static final Type myType = TypeSystem.find(Types.DATA_TYPE);
	private Operations operations = (Operations) myType.proxy(this);
	private static final StaticOperations staticOperations = (StaticOperations) myType.staticProxy();
	
	public Data(long handle) {
		super(handle, true);
	}
	
	public Data(long handle, boolean weak) {
		super(handle, weak);
	}
	
	public void Clear() {
		operations.Clear();
	}
	
    public void Resize(int size) {
    	operations.Resize(size);
    }
	
	public int GetByte(int idx) {
		return operations.GetByte(idx);
	}
	
	public void SetByte(int idx, int value) {
    	operations.SetByte(idx, value);
    }
    
	public int GetByteSize() {
    	return operations.GetByteSize();
    }
    
	public void InsertByte(int idx, int value) {
    	operations.InsertByte(idx, value);
    }
    
	public void InsertBytes(int idx, Data bytes, int start, int length) {
    	operations.InsertBytes(idx, bytes, start, length);
    }
    
	public void RemoveBytes(int start, int length) {
    	operations.RemoveBytes(start, length);
    }
	
	public static Data Create(int size) {
		return staticOperations.Create(size);
	}
	
	public interface Operations {
		void Clear();
	    void Resize(int size);
		int GetByte(int idx);
	    void SetByte(int idx, int value);
	    int GetByteSize();
	    void InsertByte(int idx, int value);
	    void InsertBytes(int idx, Data bytes, int start, int length);
	    void RemoveBytes(int start, int length);
	}
	
	public interface StaticOperations {
		Data Create(int size);
	}
}
